/**
 * time: 2025-09-16
 * author: XJ
 * description: 修改密码页面
 */

import { password } from '@/services/apis/companyRegister';
import { servicePass } from '@/services/apis/serviceProviderRegister';
import { PageContainer } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import { Button, Card, Col, Form, Input, message, Row } from 'antd';
const FORM_LAYOUT = {
  labelCol: { span: 5 },
  wrapperCol: { span: 19 },
  layout: 'horizontal' as const,
  
  size: 'middle' as const,
};
const COMMON_FIELD_STYLE = { width: '100%', height: 40, borderRadius: 4 };
const AccountManagerPage: React.FC = (props) => {
  const { initialState } = useModel('@@initialState');
  const onFinish = (values: any) => {
    if (initialState?.currentUser?.access == 'service') {
      servicePass({ ...values, id: (initialState?.currentUser.data).id }).then(res => {
        const { code } = res;
        if (code == "0") {
          //message.success("修改成功")
        }
      })
    } else if (initialState?.currentUser?.access == 'entriprise') {
      password({ ...values, id: (initialState?.currentUser?.data).id }).then(res => {
        const { code } = res;
        if (code == "0") {
          //message.success("修改成功")
        }
      })
    }
  };
  const onFinishFailed = (values: any) => {

  };
  return (
    <Card
      style={{
        margin: '16px',
        borderRadius: 12,
        boxShadow: '0 2px 8px rgba(0,0,0,0.06)',
        height: 'calc(100vh - 120px)', // 精确高度，保证内部滚动
        overflowY: 'auto', // 内部滚动
        padding: '24px',
      }}
    // bodyStyle={{
    //   padding: '24px',
    // }}
    >
      <Row justify="center">
        <Col span={20}>
          <div style={{ padding: 20, backgroundColor: '#f8f9fa', boxSizing: 'border-box' }}>
            <div
              style={{
                backgroundColor: '#fff',
                padding: 20,
                borderRadius: 8,
                boxShadow: '0 1px 3px rgba(0,0,0,0.05)',
              }}
            >
              <div style={{
                fontSize: 16,
                fontWeight: 500,
                color: '#1f2937',
                marginBottom: 12
              }}>
                修改密码
              </div>
              <Form
                {...FORM_LAYOUT}
                name="basic"
                // labelCol={{ span: 8 }}
                // wrapperCol={{ span: 16 }}
                style={{ maxWidth: '100%' }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                autoComplete="off"
              >
                <Form.Item
                  label="旧密码"
                  name="oldPassword"
                  rules={[{ required: true, message: '请输入旧密码' }]}
                >
                  <Input style={COMMON_FIELD_STYLE} />
                </Form.Item>
                <Form.Item
                  label="新密码"
                  name="password"
                  rules={[{ required: true, message: '请输入新密码' }]}
                >
                  <Input style={COMMON_FIELD_STYLE} />
                </Form.Item>
                <Form.Item
                  label="重复新密码"
                  name="newPasswordRepeat"
                  rules={[{ required: true, message: '请输入新密码' }]}
                >
                  <Input style={COMMON_FIELD_STYLE} />
                </Form.Item>
                <Form.Item style={{ marginTop: 40, textAlign: "center" }} label={null}>
                  <Button type="primary" htmlType="submit">
                    提交
                  </Button>
                </Form.Item>
              </Form>
            </div>
          </div>
        </Col>
      </Row>
    </Card>
  );
};

export default AccountManagerPage;
